// fast4j - Fast & Agile Service Tools for Java
// Copyright (C) 2007 Alexandre ROMAN
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

// $Id: ServiceContext.java 36 2007-03-27 22:02:40Z alexandre.roman $

package service.api;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Service context.
 * @author alexandre.roman
 */
public class ServiceContext implements Serializable {
    private static final long serialVersionUID = 1L;
    private long invocationTimestamp;
    private List<String> messages = new ArrayList<String>();
    private String clientHost;
    
    /**
     * Returns client hostname.
     * @return client hostname
     */
    public String getClientHost() {
        return clientHost;
    }
    
    public void setClientHost(String clientHost) {
        this.clientHost = clientHost;
    }
    
    /**
     * Returns messages attached to this context.
     * @return messages in {@link String} {@link List}
     */
    public List<String> getMessages() {
        return messages;
    }
    
    public void setMessages(List<String> messages) {
        this.messages = messages;
    }
    
    /**
     * Returns timestamp when the client request was made.
     * @return request timestamp
     */
    public long getInvocationTimestamp() {
        return invocationTimestamp;
    }
    
    public void setInvocationTimestamp(long invocationTimestamp) {
        this.invocationTimestamp = invocationTimestamp;
    }
    
    /**
     * Copy values.
     * @param source to copy
     */
    public void copyFrom(ServiceContext source) {
        invocationTimestamp = source.invocationTimestamp;
        messages = new ArrayList<String>(source.messages);
        clientHost = source.clientHost;
    }
    
    @Override
    public String toString() {
        return "ServiceContext[clientHost=" + clientHost
                + ", invocationTimestamp=" + invocationTimestamp
                + ", messages=" + messages + "]";
    }
}
